import ccclass = cc._decorator.ccclass;
import PopupWindow from "../../framework/PopupWindow";
import property = cc._decorator.property;
import { WindowName } from "../../framework/reflect/WindowName";
import Context from "../../framework/Context";
import LoadResData from "../../framework/LoadResData";
import LocalStorage from "../../framework/utils/LocalStorage";

@ccclass
@WindowName("WeaponTalent")
export default class WeaponTalent extends PopupWindow {

    @property(cc.Label)
    private curLv: cc.Label = null;
    @property(cc.Label)
    private lastLv: cc.Label = null;
    @property(cc.Label)
    private weaponName: cc.Label = null;
    @property(cc.Label)
    private skillName: cc.Label = null;

    public static sendData(data): Promise<WeaponTalent> {
        return Context.get().popup(WeaponTalent, false).then(talentInfo => {
            talentInfo.initData(data);
            return Promise.resolve(talentInfo)
        })
    }
    public onStart() {
        this.bgClickable = true
    }
    public initData(data) {
        var talentData = LoadResData.inbronData;
        var skill_type = 0, skill_base = 0, lv = 0;
        var id = data["id"];
        var weaponLv: any = LocalStorage.getObj("weaponLv");
        for (let i = 0; i < weaponLv.length; i++) {
            if (weaponLv[i]["id"] == id) {
                lv = weaponLv[i]['lv'];
            }
        }
        this.weaponName.string = data["name"];
        this.skillName.string = "天赋·" + data["skill_name"];
        skill_type = data["skill_type"];
        skill_base = data["skill_base"];
        for (let h = 0; h < talentData.length; h++) {
            if (talentData[h]["id"] == skill_type) {
                this.curLv.string = talentData[h]["desc"] + lv * skill_base;
                this.lastLv.string = talentData[h]["next"] + (lv + 1) * skill_base;
            }

        }
    }
}